/*
 *  FontListBox.cpp
 *  Typeface Builder
 *
 *  Created by David Rowland on 01/12/2008.
 *  Copyright 2008 UWE. All rights reserved.
 *
 */

#include "FontListBox.h"

FontListBox::FontListBox ()
{
	Font::findFonts (fonts);
	
	addAndMakeVisible (listBox = new ListBox (T("fonts"), this));
	listBox->setRowHeight (28);
	
	listBox->selectRow (0);
	listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.5f));
	listBox->setOutlineThickness (1);
}

FontListBox::~FontListBox ()
{
	deleteAllChildren();   // This will remove all the contained components, and delete
	// the objects for you.
}

void FontListBox::resized ()
{
	listBox->setBounds(0, 0, getWidth(), getHeight());
}

int FontListBox::getNumRows ()
{
	return fonts.size();
}

void FontListBox::paintListBoxItem (int rowNumber,
									   Graphics& g,
									   int width, int height,
									   bool rowIsSelected)
{
	if (rowIsSelected)
		g.fillAll (Colours::lightblue);
	
	if (fonts [rowNumber] != 0)
	{
		Font font (*fonts [rowNumber]);
		font.setHeight (height * 0.7f);
		
		g.setFont (font);
		g.drawText (font.getTypefaceName(),
					4, 0, width - 4, height,
					Justification::centredLeft, true);
	}
}

String FontListBox::getSelectedFont ()
{
	return fonts[listBox->getSelectedRow()]->getTypefaceName();
}